import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;

/**
 * @modulename 
 * 
 * @description 
 * 
 * @callsequence  
 * 
 * @inparam 
 * 
 * @outparam 
 * 
 * @errorstested 
 * 
 * @errorsgenerated 
 * 
 * @author
 * 
 * @createdate
 * 
 * @modlog Who/When/Why
 * 
 * Coding Standards Met: "Signed Code Leader(Jaron)"
 * 
 * Testing Standards Met: "Signed Test Leader(Jamie)"
 */
public class FileHandler {

	public static void createFile(File saveFile, String text) throws IOException, FileNotFoundException {
		try {
			File newFile = saveFile;
			if (newFile.exists()) {
				newFile.delete();
			}
			newFile.createNewFile();
			PrintStream fileOutput = new PrintStream(newFile);
			fileOutput.println(text);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			throw e;
		} catch (IOException e) {
			e.printStackTrace();
			throw e;
		}
	}

	/**
	 * @modulename 
	 * 
	 * @description 
	 * 
	 * @callsequence  
	 * 
	 * @inparam 
	 * 
	 * @outparam 
	 * 
	 * @errorstested 
	 * 
	 * @errorsgenerated 
	 * 
	 * @author
	 * 
	 * @createdate
	 * 
	 * @modlog Who/When/Why
	 * 
	 * Coding Standards Met: "Signed Code Leader(Jaron)"
	 * 
	 * Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	
	public static String readFile(File readFile) {
		String text = new String();
		try{
			Scanner scan = new Scanner(readFile);
			while (scan.hasNext()) {
				text = text + scan.nextLine() + "\n";
			}
			scan.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		return text;
	}
	
	/**
	 * @modulename 
	 * 
	 * @description 
	 * 
	 * @callsequence  
	 * 
	 * @inparam 
	 * 
	 * @outparam 
	 * 
	 * @errorstested 
	 * 
	 * @errorsgenerated 
	 * 
	 * @author
	 * 
	 * @createdate
	 * 
	 * @modlog Who/When/Why
	 * 
	 * Coding Standards Met: "Signed Code Leader(Jaron)"
	 * 
	 * Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	
	public static void writeFile(File writeFile, String text) throws FileNotFoundException {
		try {
			File newFile = writeFile;
			PrintStream fileOutput = new PrintStream(newFile);
			fileOutput.println(text);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			throw e;
		}
	}
	
	/**
	 * @modulename 
	 * 
	 * @description 
	 * 
	 * @callsequence  
	 * 
	 * @inparam 
	 * 
	 * @outparam 
	 * 
	 * @errorstested 
	 * 
	 * @errorsgenerated 
	 * 
	 * @author
	 * 
	 * @createdate
	 * 
	 * @modlog Who/When/Why
	 * 
	 * Coding Standards Met: "Signed Code Leader(Jaron)"
	 * 
	 * Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	
	public static void resetFile(File resetFile) throws IOException {
		if (resetFile.exists()) {
			try {
				resetFile.delete();
				resetFile.createNewFile();
			} catch (IOException e) {
				e.printStackTrace();
				throw e;
			}
		}
	}
}